<template>
  <div class="couponsEcharts">
    <el-row :gutter="20">
      <el-col :span="20">
        <div class="echarts">
          <div id="myChart" :style="{width: '100%', height: '600px'}"></div>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import request from '@/utils/request'

const echarts = require('echarts/lib/echarts')
require('echarts/lib/component/tooltip')
require('echarts/lib/component/title')
require('echarts/lib/component/legend')
export default {
  name: 'CouponsEcharts',
  data () {
    return {
      data: []
    }
  },
  mounted () {
  },
  created () {
    this.getData()
  },
  methods: {
    async getData () {
      const { data: res } = await request.postJson('/getCouponNum', {})
      res.data.forEach(item => {
        this.data.push({
          value: item.num,
          name: item.title
        })
      })
      const myChart = echarts.init(document.getElementById('myChart'))
      myChart.setOption({
        title: {
          text: '优惠卷使用占比图',
          left: 'center'
        },
        tooltip: {
          trigger: 'item'
        },
        toolbox: {
          feature: {
            saveAsImage: {}
          }
        },
        legend: {
          orient: 'vertical',
          bottom: 'bottom'
        },
        series: [
          {
            name: '使用人数',
            type: 'pie',
            radius: '50%',
            data: this.data,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      })
      console.log(this.data)
    }
  }
}
</script>

<style scoped lang='scss'>

</style>
